package fr.upmc.cie.ext;

import android.R.drawable;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Utils {

	/**
	 * Affichier une boite d'alert avec message donnee
	 * @param context
	 * @param message
	 */
	public static void getAlertBox(Context context, String message) {
		AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
		alertbox.setIcon(drawable.ic_dialog_alert);
		alertbox.setTitle("Erreur");
		alertbox.setMessage(message);
		alertbox.setNeutralButton("OK", new OnClickListener(){
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		});
		alertbox.show();
	}
	
	/**
	 * Tester la connectivite de la telephone
	 * @param context
	 * @return
	 */
	public static boolean IsConnectedToNetwork(Context context){
		ConnectivityManager conManager = (ConnectivityManager)
        context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] allNetworkInfo = conManager.getAllNetworkInfo();
        NetworkInfo currNetworkInfo;
        boolean anythingConnected = false;
        for (int i = 0; i < allNetworkInfo.length; i++)
        {
            currNetworkInfo = allNetworkInfo[i];
            if (currNetworkInfo.getState() == NetworkInfo.State.CONNECTED)
               anythingConnected = true;
        }
         return anythingConnected;
    } 
}
